if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_machblog_blocked_ip_machblog_blocked_ip]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_blocked_ip] DROP CONSTRAINT FK_machblog_blocked_ip_machblog_blocked_ip
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_comment_entry]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_comment] DROP CONSTRAINT FK_comment_entry
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_machblog_trackback_machblog_entry]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_trackback] DROP CONSTRAINT FK_machblog_trackback_machblog_entry
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_machblog_aggregator_machblog_user]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_aggregator] DROP CONSTRAINT FK_machblog_aggregator_machblog_user
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_machblog_aggregator_machblog_user1]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_aggregator] DROP CONSTRAINT FK_machblog_aggregator_machblog_user1
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_machblog_blocked_ip_machblog_user]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_blocked_ip] DROP CONSTRAINT FK_machblog_blocked_ip_machblog_user
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_category_users]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_category] DROP CONSTRAINT FK_category_users
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_category_users1]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_category] DROP CONSTRAINT FK_category_users1
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_machblog_comment_machblog_user]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_comment] DROP CONSTRAINT FK_machblog_comment_machblog_user
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_machblog_comment_machblog_user1]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_comment] DROP CONSTRAINT FK_machblog_comment_machblog_user1
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_entry_users]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_entry] DROP CONSTRAINT FK_entry_users
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_entry_users1]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_entry] DROP CONSTRAINT FK_entry_users1
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_machblog_subscriber_machblog_user]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_subscriber] DROP CONSTRAINT FK_machblog_subscriber_machblog_user
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_machblog_trackback_machblog_user]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_trackback] DROP CONSTRAINT FK_machblog_trackback_machblog_user
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_machblog_trackback_machblog_user1]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_trackback] DROP CONSTRAINT FK_machblog_trackback_machblog_user1
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_users_users]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_user] DROP CONSTRAINT FK_users_users
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_users_users1]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[machblog_user] DROP CONSTRAINT FK_users_users1
GO

/****** Object:  Table [dbo].[machblog_aggregator]    Script Date: 8/28/2006 10:23:26 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[machblog_aggregator]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[machblog_aggregator]
GO

/****** Object:  Table [dbo].[machblog_blocked_ip]    Script Date: 8/28/2006 10:23:26 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[machblog_blocked_ip]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[machblog_blocked_ip]
GO

/****** Object:  Table [dbo].[machblog_category]    Script Date: 8/28/2006 10:23:26 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[machblog_category]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[machblog_category]
GO

/****** Object:  Table [dbo].[machblog_comment]    Script Date: 8/28/2006 10:23:26 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[machblog_comment]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[machblog_comment]
GO

/****** Object:  Table [dbo].[machblog_entry]    Script Date: 8/28/2006 10:23:26 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[machblog_entry]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[machblog_entry]
GO

/****** Object:  Table [dbo].[machblog_entry_category]    Script Date: 8/28/2006 10:23:26 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[machblog_entry_category]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[machblog_entry_category]
GO

/****** Object:  Table [dbo].[machblog_subscriber]    Script Date: 8/28/2006 10:23:26 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[machblog_subscriber]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[machblog_subscriber]
GO

/****** Object:  Table [dbo].[machblog_trackback]    Script Date: 8/28/2006 10:23:26 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[machblog_trackback]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[machblog_trackback]
GO

/****** Object:  Table [dbo].[machblog_user]    Script Date: 8/28/2006 10:23:26 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[machblog_user]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[machblog_user]
GO

/****** Object:  Table [dbo].[machblog_aggregator]    Script Date: 8/28/2006 10:23:33 AM ******/
CREATE TABLE [dbo].[machblog_aggregator] (
	[aggregator_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[aggregator_name] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[aggregator_description] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[aggregator_url] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[ping_url] [nvarchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[auto_ping] [tinyint] NOT NULL ,
	[dt_last_pinged] [bigint] NULL ,
	[created_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[dt_created] [bigint] NOT NULL ,
	[ip_created] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[modified_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[dt_modified] [bigint] NULL ,
	[ip_modified] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[is_active] [tinyint] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[machblog_blocked_ip]    Script Date: 8/28/2006 10:23:33 AM ******/
CREATE TABLE [dbo].[machblog_blocked_ip] (
	[blocked_ip] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[created_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[dt_created] [bigint] NOT NULL ,
	[ip_created] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[machblog_category]    Script Date: 8/28/2006 10:23:34 AM ******/
CREATE TABLE [dbo].[machblog_category] (
	[category_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[category_name] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[created_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[dt_created] [bigint] NOT NULL ,
	[ip_created] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[modified_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[dt_modified] [bigint] NULL ,
	[ip_modified] [varchar] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[is_active] [tinyint] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[machblog_comment]    Script Date: 8/28/2006 10:23:34 AM ******/
CREATE TABLE [dbo].[machblog_comment] (
	[comment_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[entry_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[name] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[email] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[url] [nvarchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[comment] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[is_subscribed] [tinyint] NOT NULL ,
	[subscription_only] [tinyint] NULL ,
	[subscriber_email_sent] [tinyint] NULL ,
	[created_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[dt_created] [bigint] NOT NULL ,
	[ip_created] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[modified_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[dt_modified] [bigint] NULL ,
	[ip_modified] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[is_active] [tinyint] NOT NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

/****** Object:  Table [dbo].[machblog_entry]    Script Date: 8/28/2006 10:23:34 AM ******/
CREATE TABLE [dbo].[machblog_entry] (
	[entry_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[title] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[body] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[more_body] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[allow_comments] [tinyint] NULL ,
	[allow_trackbacks] [tinyint] NULL ,
	[dt_posted] [bigint] NOT NULL ,
	[photo] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[enclosure] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[enclosure_mime_type] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[enclosure_size] [decimal](18, 0) NULL ,
	[num_views] [int] NOT NULL ,
	[subscriber_email_sent] [tinyint] NULL ,
	[created_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[dt_created] [bigint] NOT NULL ,
	[ip_created] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[modified_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[dt_modified] [bigint] NULL ,
	[ip_modified] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[is_active] [tinyint] NOT NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

/****** Object:  Table [dbo].[machblog_entry_category]    Script Date: 8/28/2006 10:23:34 AM ******/
CREATE TABLE [dbo].[machblog_entry_category] (
	[entry_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[category_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[machblog_subscriber]    Script Date: 8/28/2006 10:23:34 AM ******/
CREATE TABLE [dbo].[machblog_subscriber] (
	[subscriber_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[subscriber_email] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , 
	[verify_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[created_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[dt_created] [bigint] NOT NULL ,
	[ip_created] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[modified_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[dt_modified] [bigint] NULL ,
	[ip_modified] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[is_active] [tinyint] NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[machblog_trackback]    Script Date: 8/28/2006 10:23:35 AM ******/
CREATE TABLE [dbo].[machblog_trackback] (
	[trackback_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[trackback_title] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[trackback_excerpt] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[trackback_url] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[trackback_blog_name] [nvarchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[entry_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[created_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[dt_created] [bigint] NOT NULL ,
	[ip_created] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[modified_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[dt_modified] [bigint] NULL ,
	[ip_modified] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[is_active] [tinyint] NOT NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

/****** Object:  Table [dbo].[machblog_user]    Script Date: 8/28/2006 10:23:35 AM ******/
CREATE TABLE [dbo].[machblog_user] (
	[user_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[email] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[password] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[password_salt] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[first_name] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[last_name] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[dt_last_access] [bigint] NULL ,
	[ip_last_access] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[created_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[dt_created] [bigint] NOT NULL ,
	[ip_created] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[modified_by_id] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[dt_modified] [bigint] NULL ,
	[ip_modified] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[is_active] [tinyint] NOT NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[machblog_aggregator] ADD 
	CONSTRAINT [PK_machblog_aggregator] PRIMARY KEY  CLUSTERED 
	(
		[aggregator_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[machblog_blocked_ip] ADD 
	CONSTRAINT [PK__machblog_blocked__00551192] PRIMARY KEY  CLUSTERED 
	(
		[blocked_ip]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[machblog_category] ADD 
	CONSTRAINT [PK_category] PRIMARY KEY  CLUSTERED 
	(
		[category_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[machblog_comment] ADD 
	CONSTRAINT [PK_comment] PRIMARY KEY  CLUSTERED 
	(
		[comment_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[machblog_entry] ADD 
	CONSTRAINT [DF_machblog_entry_num_views] DEFAULT (0) FOR [num_views],
	CONSTRAINT [PK_entry] PRIMARY KEY  CLUSTERED 
	(
		[entry_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[machblog_entry_category] ADD 
	CONSTRAINT [PK_entry_category] PRIMARY KEY  CLUSTERED 
	(
		[entry_id],
		[category_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[machblog_subscriber] ADD 
	CONSTRAINT [PK_machblog_subscriber] PRIMARY KEY  CLUSTERED 
	(
		[subscriber_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[machblog_trackback] ADD 
	CONSTRAINT [PK_machblog_trackback] PRIMARY KEY  CLUSTERED 
	(
		[trackback_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[machblog_user] ADD 
	CONSTRAINT [PK_users] PRIMARY KEY  CLUSTERED 
	(
		[user_id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[machblog_aggregator] ADD 
	CONSTRAINT [FK_machblog_aggregator_machblog_user] FOREIGN KEY 
	(
		[created_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	),
	CONSTRAINT [FK_machblog_aggregator_machblog_user1] FOREIGN KEY 
	(
		[modified_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	)
GO

ALTER TABLE [dbo].[machblog_blocked_ip] ADD 
	CONSTRAINT [FK_machblog_blocked_ip_machblog_blocked_ip] FOREIGN KEY 
	(
		[blocked_ip]
	) REFERENCES [dbo].[machblog_blocked_ip] (
		[blocked_ip]
	),
	CONSTRAINT [FK_machblog_blocked_ip_machblog_user] FOREIGN KEY 
	(
		[created_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	)
GO

ALTER TABLE [dbo].[machblog_category] ADD 
	CONSTRAINT [FK_category_users] FOREIGN KEY 
	(
		[created_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	),
	CONSTRAINT [FK_category_users1] FOREIGN KEY 
	(
		[modified_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	)
GO

ALTER TABLE [dbo].[machblog_comment] ADD 
	CONSTRAINT [FK_comment_entry] FOREIGN KEY 
	(
		[entry_id]
	) REFERENCES [dbo].[machblog_entry] (
		[entry_id]
	),
	CONSTRAINT [FK_machblog_comment_machblog_user] FOREIGN KEY 
	(
		[created_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	),
	CONSTRAINT [FK_machblog_comment_machblog_user1] FOREIGN KEY 
	(
		[modified_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	)
GO

ALTER TABLE [dbo].[machblog_entry] ADD 
	CONSTRAINT [FK_entry_users] FOREIGN KEY 
	(
		[created_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	),
	CONSTRAINT [FK_entry_users1] FOREIGN KEY 
	(
		[modified_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	)
GO

ALTER TABLE [dbo].[machblog_subscriber] ADD 
	CONSTRAINT [FK_machblog_subscriber_machblog_user] FOREIGN KEY 
	(
		[created_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	)
GO

ALTER TABLE [dbo].[machblog_trackback] ADD 
	CONSTRAINT [FK_machblog_trackback_machblog_entry] FOREIGN KEY 
	(
		[entry_id]
	) REFERENCES [dbo].[machblog_entry] (
		[entry_id]
	),
	CONSTRAINT [FK_machblog_trackback_machblog_user] FOREIGN KEY 
	(
		[created_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	),
	CONSTRAINT [FK_machblog_trackback_machblog_user1] FOREIGN KEY 
	(
		[modified_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	)
GO

ALTER TABLE [dbo].[machblog_user] ADD 
	CONSTRAINT [FK_users_users] FOREIGN KEY 
	(
		[created_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	),
	CONSTRAINT [FK_users_users1] FOREIGN KEY 
	(
		[modified_by_id]
	) REFERENCES [dbo].[machblog_user] (
		[user_id]
	)
GO



INSERT INTO [dbo].[machblog_user]([user_id], [email], [password], [password_salt], [first_name], [last_name], [created_by_id], [dt_created], [ip_created], [is_active])
VALUES('F2D2EE50-1111-1927-82EDC2833CAC6792','admin@admin.com','F4CB632BBD5D93F18AE1F2723CBF6D63C188B4B8','3BD04BF0-1111-1927-829D2D609000BD42','Default','User','F2D2EE50-1111-1927-82EDC2833CAC6792',DATEDIFF(s, '19700101', GETDATE()),'0.0.0.0',1)

GO


/**************************************************************************************************************
*   blogCFC to MachBlog Migration Script 
*   version 1.0
*   1/18/2007
*   Created By:  Andrew Powell (andrew.powell@universalmind.com)
*
*   This script was created to help users migrate their blogs from blogCFC to MachBlog.
*   Some assumptions are made:
*   1.  All entries are created by one user
*   2.  Only one blog was used in the blogCFC database
*   3.  Your MachBlog and blogCFC data reside in the same database
*   4.  Any dates that do not exist in the blogCFC database will be replaced by a timestamp of the current time
*   5.  You are administering your users already via MachBlog
*
*
*   You can change the user used as the default entry user to your user of choice.
***************************************************************************************************************/

//These are variables we will use throughout this script
declare @user char(35)
declare @fullName nvarchar(101)
declare @createDate bigint

set @user = (select user_id from machblog_user WHERE first_name ='Default' AND last_name = 'User')
set @createDate = cast((CAST(DATEDIFF(s,'19700101',getDate()) as varchar(50)) + '000') as bigint)
set @fullName = (SELECT (first_name + ' ' + last_name) FROM machblog_user WHERE user_id = @user)

//This is the section to migrate categories to machBlog
BEGIN
    INSERT INTO machblog_category(category_id,category_name,created_by_id,dt_created,ip_created,is_active) 
    SELECT categoryID, categoryName, @user, @createDate, '0.0.0.0', 1 FROM tblBlogCategories
END

//This is the section to migrate entries to machBlog
BEGIN
    INSERT INTO machblog_entry(entry_id,title,body,dt_posted, dt_created,more_body,created_by_id,allow_comments,enclosure,enclosure_size,enclosure_mime_type,num_views,is_active,subscriber_email_sent,ip_created,allow_trackbacks)
    SELECT id, title, body, cast((CAST(DATEDIFF(s,'19700101',posted) as varchar(50)) + '000') as bigint), cast((CAST(DATEDIFF(s,'19700101',posted) as varchar(50)) + '000') as bigint),morebody,@user,allowcomments,enclosure,filesize,mimetype,views,released,mailed,'0.0.0.0',0 FROM tblBlogEntries
END

//Ths is the section to associate categories with entries
BEGIN
    INSERT INTO machblog_entry_category(entry_id,category_id) 
    SELECT entryIDFK,categoryIDFK FROM tblBlogEntriesCategories
END

//This is the section to associate comments with entries
BEGIN
    INSERT INTO machblog_comment(comment_id,entry_id,[name],email,comment,dt_created,is_subscribed,url,is_active,ip_created) 
    SELECT id,entryidfk,[name],email,comment,cast((CAST(DATEDIFF(s,'19700101',posted) as varchar(50)) + '000') as bigint),subscribe,website,1,'0.0.0.0' FROM tblBlogComments
END

//This is the section to migrate subscribers
BEGIN
    INSERT INTO machblog_subscriber(subscriber_id,subscriber_email,dt_created,ip_created,is_active)
    SELECT token,email,@createDate,'0.0.0.0',1 FROM tblBlogSubscribers
END

//This is the section to migrate trackbacks
BEGIN
    INSERT INTO machblog_trackback(trackback_id,trackback_title,trackback_blog_name,trackback_url,trackback_excerpt,dt_created,entry_id,ip_created,is_active) 
    SELECT id,title,blogname,posturl,excerpt,cast((CAST(DATEDIFF(s,'19700101',created) as varchar(50)) + '000') as bigint),entryid,'0.0.0.0',1 FROM tblBlogTrackBacks
END
GO